package com.neu.his.fmeditem.serviceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.excel.EasyExcel;
import com.neu.his.department.entity.Department;
import com.neu.his.department.listener.DepartmentListener;
import com.neu.his.fmeditem.entity.Fmeditem;
import com.neu.his.fmeditem.entity.FmeditemVo;
import com.neu.his.fmeditem.listener.FmeditemExcel;
import com.neu.his.fmeditem.listener.FmeditemListener;
import com.neu.his.fmeditem.mapper.FmeditemMapper;
import com.neu.his.fmeditem.service.FmeditemService;

@Service
public class FmeditemServiceImpl implements FmeditemService{
	@Autowired
	private FmeditemMapper fmeditemMapper;

	@Override
	public boolean addFmeditem(Fmeditem fmeditem) {
		System.out.println(fmeditem);
		int value = fmeditemMapper.addFmeditem(fmeditem);
		boolean flag=false;
		if(value>0) {
			return flag=true;
		}
		return flag;
	}

	@Override
	public boolean deleteFmeditem(int id) {
		int value = fmeditemMapper.deleteFmeditem(id);
		boolean flag=false;
		if(value>0) {
			return flag=true;
		}
		return flag;
	}

	@Override
	public boolean delFmeditemByIds(Integer[] ids) {
		int value = fmeditemMapper.delFmeditemByIds(ids);
		boolean flag=false;
		if(value==ids.length) {
			return flag=true;
		}
		return flag;
	}

	@Override
	public boolean updateFmeditem(Fmeditem fmeditem) {
		int value = fmeditemMapper.updateFmeditem(fmeditem);
		boolean flag=false;
		if(value>0) {
			return flag=true;
		}
		return flag;
	}

	@Override
	public List<FmeditemVo> pageFmeditem(int page, int limit, String itemName, int recordType) {
		List<FmeditemVo> list = fmeditemMapper.pageFmeditem(page, limit, itemName, recordType);
		return list;
	}

	@Override
	public int pageFmeditemTotal(String itemName, int recordType) {
		
		return fmeditemMapper.pageFmeditemTotal(itemName, recordType);
	}

	@Override
	public void exportExcel(HttpServletResponse response) {
		String filename="D:\\fmeditem.xlsx";
		List<Fmeditem> list = fmeditemMapper.findAll();	    
		EasyExcel.write(filename,FmeditemExcel.class).sheet("非药品收费项").doWrite(list);
	}

	@Override
	public void importExcel(MultipartFile file) {		
		try {
			InputStream inputStream = file.getInputStream();
			EasyExcel.read(inputStream,Fmeditem.class,new FmeditemListener(fmeditemMapper)).sheet().doRead();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
}
